$def with (page)

$# Most authors are people, so only use org in the exceptional case that
$# the record explicitly is labelled as such.
$if page.entity_type == 'org':
    $ entityTypeSchema = "https://schema.org/Organization"
$else:
    $ entityTypeSchema = "https://schema.org/Person"

$ bodyattrs = ctx.setdefault('bodyattrs', [])
$ bodyattrs.append('itemscope')
$ bodyattrs.append('itemtype="%s"' % entityTypeSchema)

$ title = page.get('name', _('name missing'))
$ title_with_site = _("%(page_title)s | Open Library", page_title=title)
$ meta_photo_url = item_image(page.get_photo_url("L"), "https://openlibrary.org/images/icons/avatar_author-lg.png")

$var title: $title
$var history: $page.history

$ olid = page.key.split('/')[-1]

$ books = page.get_books(q=query_param('q'))
$ book_list_excerpt = ''
$if books and books.docs:
    $ book_titles_excerpt = [work.title for work in books.docs[:8]]
    $ book_list_excerpt = ', '.join(book_titles_excerpt)

$ books_count = books.num_found or 0

$ description = _("Author of %(book_titles)s", book_titles=book_list_excerpt)
$putctx("description", description)

$add_metatag(property="og:title", content=title_with_site)
$add_metatag(property="og:type", content="books.author")
$add_metatag(property="og:image", content=meta_photo_url)
$add_metatag(property="og:url", content=request.canonical_url)
$add_metatag(property="og:site_name", content="Open Library")
$add_metatag(property="og:description", content=description)

$set_share_links(url=request.canonical_url, title=title, view_context=ctx)

$ show_librarian_extras = ctx.user and (ctx.user.is_admin() or ctx.user.is_librarian())
<div id="contentHead">

    $:macros.databarView(page)

    <h1 itemprop="name">$title</h1>
    $if show_librarian_extras:
        <h2 class="author collapse">
            $if page.birth_date or page.death_date:
                <span itemprop="birthDate">$page.birth_date</span> - <span itemprop="deathDate">$page.death_date</span>
            $else:
                $if page.date:
                    $page.date
        </h2>

</div>

<div id="contentBody">
    $if ctx.user and ("merge-authors" in ctx.features or ctx.user.is_admin()) and query_param('merge', 'false') == 'true':
        $ mrid = query_param('mrid', None)
        $ comment = query_param('comment', None)
        $ duplicate_olids = query_param('duplicates', '').split(',')
        $ duplicates = ["/authors/" + k for k in duplicate_olids]
        $ data = {'master': page.key, 'duplicates': duplicates}
        $if mrid:
            $ data['mrid'] = mrid
        $if comment:
            $ data['comment'] = comment

        $ olids = '%s,%s' % (page.key.split('/')[-1], query_param('duplicates', ''))
        $ data['olids'] = olids

        <div class="message" style="display: none;">
            <div id="preMerge" style="display: none;" data-keys="$dumps(data)">
                <p class="larger collapse"><strong>$_('Merging Authors...')</strong></p>
                <p class="collapse adjust"><img src="/images/ajax-loader-bar.gif" width="220" height="19" alt="$_('In progress...')"/></p>
                <p class="smaller lightgreen collapse">$_('Duplicates')</p>
                <p class="small collapse">
                    <ul>
                        $for key in duplicates:
                             $ doc = get_document(key)
                             $if doc:
                                 <li> $doc.name; <small>($key)</small></li>
                    </ul>
                </p>
            </div>
            <div id="postMerge" style="display: none;">
                <p class="right small"><b><a href="$page.key">$_('Refresh the page?')</a></b></p>
                <p class="larger collapse"><strong>$_('Success!')</strong></p>
                <p class="small collapse">$:_('OK. The merge is in motion. <i>It will take <u>a few minutes to finish</u> the update.</i>')</p>
            </div>

            <div id="errorMerge" style="display: none;">
                <p class="larger collapse"><strong>$_('Argh!')</strong></p>
                <p class="small collapse">$_("That merge didn't work. It's our fault, and we've made a note of it.")</p>
            </div>
        </div>

    <div class="contentTwothird" style="margin-bottom:0;">

        <div itemprop="description">
            $:format(page.get('bio', ''))
        </div>

        $if page.location:
            <div class="section hidden">
                <h6 class="collapse black uppercase">$_("Location")</h6>
                $page.location
            </div>
        <span class="mobile-only">
            $:render_template("authors/infobox", page, imagesId="mobile")
        </span>
        <div class="clearfix"></div>
        <div id="works" class="section">
                <h2 class="collapse">
                    $ungettext("%(count)d work", "%(count)d works", books_count, count=books_count)
                    <span class="count smaller"><a href="/books/add?author=$page.key">$_('Add another?')</a></span>
                </h2>
                $if books_count > 1:
                  <div id="books">
                    $:render_template("search/sort_options.html", books.sort, exclude='relevance', default_sort='editions')
                  </div>
                <p>
                  $if input(mode="everything").mode == "everything":
                    $:_('Showing all works by author. Would you like to see <a href="%(url)s">only ebooks</a>?', url=changequery(mode='ebooks'))
                  $else:
                    $:_('Showing ebooks only. Would you like to see <a href="%(url)s">everything</a> by this author?', url=changequery(mode='everything'))
                </p>

                <form method="GET" class="olform pagesearchbox">
                  <input type="hidden" name="has_fulltext" value="true"/>
                  $if (query_param('sort')):
                    <input type="hidden" name="sort" value="$query_param('sort')"/>
                  $if (query_param('mode')):
                    <input type="hidden" name="mode" value="$query_param('mode')"/>
                  $:render_template("search/searchbox", q=query_param('q'), placeholder=_('Search %(author)s books', author=title))
                </form>

                $:macros.Pager(page=safeint(query_param('page'), default=1), num_found=books_count)

                <div id="searchResults">
                    <ul class="list-books">
                      $for doc in books.docs:
                         $:macros.SearchResultsWork(doc, show_librarian_extras=show_librarian_extras, include_dropper=True)
                    </ul>
                </div>

                $:macros.Pager(page=safeint(query_param('page'), default=1), num_found=books_count)
        </div>
    </div>
    <div class="contentOnethird">
        <span class="desktop-only">
            $:render_template("authors/infobox", page, imagesId="desktop")
        </span>
        $def render_subjects(label, subjects, prefix):
            $if subjects:
                <div class="section link-box link-box--with-header">
                    <h3 class="collapse black uppercase">$label</h3>
                    $for _, subject, count in subjects:
                        <a itemprop="knowsAbout" href="/subjects/$prefix$subject.lower().replace(' ', '_')">$subject</a>$cond(not loop.last, ",", "")
                </div>

        <!-- SUBJECTS DISPLAY -->
        $if books_count > 0:
            $:render_subjects(_("Subjects"), books.facet_counts.get('subject_facet'), '')
            $:render_subjects(_("Places"), books.facet_counts.get('place_facet'), 'place:')
            $:render_subjects(_("People"), books.facet_counts.get('person_facet'), 'person:')
            $:render_subjects(_("Time"), books.facet_counts.get('time_facet'), 'time:')
        <!-- /SUBJECTS -->

        $if "lists" in ctx.features:
            <div class="section Tools">
                $:render_template("lists/widget", page, include_rating=False, async_load=True, show_active_lists=True, include_showcase=False)
            </div>

        <div class="section">
            <h3>$_('ID Numbers')</h3>
            <ul class="booklinks sansserif">
                <li>$_('OLID'): $olid</li>
                $if page.remote_ids:
                    $ configured_ids = get_identifier_config('author')['identifiers']
                    $for id in configured_ids:
                        $if id.name in page.remote_ids:
                            $ href = id.url.replace('@@@', page.remote_ids[id.name])
                            <li>$id.label: <a itemprop="sameAs" href="$href">$page.remote_ids[id.name]</a></li>
                            $if id.name == 'wikidata' and 'inventaire' not in page.remote_ids:
                              <li>$_("Inventaire.io:") <a
                                  itemprop="sameAs"
                                  href="https://inventaire.io/entity/wd:$page.remote_ids[id.name]"
                              >wd:$page.remote_ids[id.name]</a></li>
            </ul>
        </div>

        <div class="section">
            <h3>$:_('Links <span class="gray small sansserif">outside Open Library</span>')</h3>

            $if page.links:
                <ul class="booklinks sansserif">
                $for link in page.links:
                    <li><a href="$link.url">$link.title</a></li>
                </ul>
            $else:
                <p class="sansserif small">$_('No links yet.') <a href="$page.url('/edit')#web">$_('Add one')</a>?</p>

        </div>

        $if page.alternate_names:
            $if page.alternate_names != [""]:
                <div class="section">
                    <h3>$_("Alternative names")</h3>
                    <ul class="booklinks sansserif">
                        $for alternate_name in page.alternate_names:
                            <li itemprop="alternateName">$alternate_name</li>
                    </ul>
                </div>

    </div>

    $:render_template("lib/history", page)
</div>
